package com.zat.mes.andrmes.dofun.main.vm

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.love.zywanandroid.retrofit.RetrofitManager
import com.love.zywanandroid.retrofit.api.ApiService
import com.zat.mes.andrmes.data.BaseResponse
import com.zat.mes.andrmes.data.CheckApkBean
import com.zat.mes.andrmes.retrofit.callback.MesCallBack
import retrofit2.Call
import retrofit2.Response

/**
 * @author zy
 * @date :2020-02-20 09:58
 * @description:app更新model
 */
class ApkModel : ViewModel() {


    private val apkData: MutableLiveData<CheckApkBean> = MutableLiveData()

    fun getApkBean(): MutableLiveData<CheckApkBean> {
        return apkData
    }

    /**
     * 检查版本更新
     */
    fun loadCheckVersion(versionCode: String) {
        RetrofitManager.apiService(ApiService::class.java)
            .getCheckApk(versionCode)
            .enqueue(object : MesCallBack<BaseResponse<CheckApkBean>>() {
                override fun onSuccessful(
                    call: Call<BaseResponse<CheckApkBean>>?,
                    response: Response<BaseResponse<CheckApkBean>>?
                ) {
                    apkData.postValue(response?.body()?.result)
                }

            })
    }

    /**
     * 下载apk
     */
    fun downApk(url: String) {
    }

}